package org.trajectory.dao;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.cfa.sql.DBConnection;


/**
 * 
 * @Author Cloud
 * @Date 2011-9-5
 * @File BaseDao.java
 * @Summary
 */
public abstract class BaseDao {
	/**
	 * Database Connection
	 */
	protected DBConnection conn;

	public BaseDao() {
		conn = new DBConnection("jdbc:mysql://localhost/jewelry", "root", "icmdb2010", "com.mysql.jdbc.Driver");
	}

	public BaseDao(DBConnection conn) {
		this.conn = conn;
	}
	
	
	protected void appendValue(StringBuffer str , Object value){
		if(value instanceof String){
			str.append("'");
			str.append(String.valueOf(value));
			str.append("'");
		}else {
			str.append(String.valueOf(value));
		}
	}
	protected Object getValue(Entry e){
		Object o = e.getValue();
		if(o instanceof String[]){
			return ((String[])o)[0];
		}else if(o instanceof String){
			return o;
		}else if(o instanceof Integer){
			return Integer.parseInt(o.toString());
		}else if(o instanceof Boolean){
			return Boolean.parseBoolean(o.toString());
		}
		return o;
	}
}
